﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using userManagement;
using userInteractveControllers;

namespace WebInterface.Public
{
    public partial class CreateNewUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            UsersDataPersister usersDataPersister = UsersDataPersister.getInstance();
            userManagement.User user = usersDataPersister.getUser(txtUsername.Text);
            if (user == null)
            {
                user = new userManagement.User();
                user.name = txtUsername.Text;
                user.setNewPassword(txtPassword.Text);
                usersDataPersister.addUser(user);
                usersDataPersister.storeUsers();
                user.setCredit(10000M);
                
                string gotoPage = null;
                LoginController loginController = new LoginController();
                gotoPage = loginController.login(txtUsername.Text, txtPassword.Text);
                if (gotoPage != null)
                {
                    Response.Redirect("../GameGUI.aspx");
                }

            }
            else
            {
                lblAlreadyExists.Visible = true;
            }

        }
    }
}
